<?php
if (!isset($id)) $id = 0;
if (!isset($page)) $page = 0;
$id += 0;
$page += 0;
?>
<?php if ($id) : ?>
	<?php
    $q = $db->query("SELECT * FROM gallery_menu WHERE id = '".$id."'");
    $r = $db->fetch($q);
    ?>
    <div class="breadcrumb">
        <a href="/" title="<?php echo get_title(); ?>">Trang chủ</a> &raquo; <a href="/<?php echo lg_string::get_link("thư viện")?>">Thư viện</a> &raquo; <span><?php echo $r['ten']?></span>
    </div>
	
	<div class="box_title">
        <h1><?php echo $r['ten']?></h1>
    </div>
	
	<?php
    $index = 0;
    $query 		= 	"SELECT * FROM gallery WHERE hien_thi = 1 AND hinh <> 'no' AND cat = '".$id."' ";
    $page		=	$page + 0;
    $perpage	=	get_bien("san_pham_show");
    $r_all		=	$db->query($query);
    $sum		=	$db->num_rows($r_all);
    $pages		=	($sum-($sum%$perpage))/$perpage;
    if ($sum % $perpage <> 0 )	$pages = $pages+1;
    $page		=	($page==0)?1:(($page>$pages)?$pages:$page);
    $min 		= 	abs($page-1) * $perpage;
    $max 		= 	$perpage;
    $q1			=	$db->query($query." ORDER BY time DESC LIMIT ".$min.", ".$max);
    ?>
    <?php if($db->num_rows($q1) != 0) : ?>
        <?php while ($r1 = $db->fetch($q1)): ?>
            <div class="box_product <?php echo (((++$index) % 3) == 2)?"box_product_center":""?>">
                <div class="box_product_title" style="text-align:center; color:#002c7d">
                    <?php echo lg_string::crop($r1['ten'], 7)?>
                </div>
                <div class="box_product_image" style="height:250px;">
                    <a class="example_group" href="/uploads/gal/<?php echo $r1['hinh']?>" title="<?php echo $r1['ten']?>">
                        <img src="/uploads/gal/thumb_<?php echo $r1['hinh']?>" alt="<?php echo $r1['ten']?>" />
                    </a>
                </div>
            </div>
        <?php endwhile; ?>
        <div class='clearfix'></div>
        <?php showPageNavigation($page, $pages, '/thu-vien/'.$id.'/'); ?>
    <?php endif; ?>
<?php else : ?>
    <div class="breadcrumb">
        <a href="/" title="<?php echo get_title(); ?>">Trang chủ</a> &raquo; <span>Thư viện</span>
    </div>
    <div class="box_title">
        <h1>Thư viện</h1>
    </div>
    
	<?php
    $index = 0;
    $query 		= 	"SELECT a.*, b.hinh FROM gallery_menu AS a, gallery AS b WHERE a.hien_thi = 1 AND b.hinh <> 'no' AND a.cat = 'thu_vien' AND b.hien_thi = 1 AND a.id = b.cat GROUP BY a.id ";
    $page		=	$page + 0;
    $perpage	=	get_bien("san_pham_show");
    $r_all		=	$db->query($query);
    $sum		=	$db->num_rows($r_all);
    $pages		=	($sum-($sum%$perpage))/$perpage;
    if ($sum % $perpage <> 0 )	$pages = $pages+1;
    $page		=	($page==0)?1:(($page>$pages)?$pages:$page);
    $min 		= 	abs($page-1) * $perpage;
    $max 		= 	$perpage;
    $q1			=	$db->query($query." ORDER BY time DESC LIMIT ".$min.", ".$max);
    ?>
    <?php if($db->num_rows($q1) != 0) : ?>
        <?php while ($r1 = $db->fetch($q1)): ?>
            <div class="box_product <?php echo (((++$index) % 3) == 2)?"box_product_center":""?>">
                <div class="box_product_title" style="text-align:center;">
                    <a href="/thu-vien/<?php echo $r1['id']?>/<?php echo lg_string::get_link($r1['ten'])?>">
                        <?php echo lg_string::crop($r1['ten'], 7)?>
                    </a>
                </div>
                <div class="box_product_image">
                    <a href="/thu-vien/<?php echo $r1['id']?>/<?php echo lg_string::get_link($r1['ten'])?>" title="<?php echo $r1['ten']?>">
                        <img src="/uploads/gal/thumb_<?php echo $r1['hinh']?>" alt="<?php echo $r1['ten']?>" />
                    </a>
                </div>
            </div>
        <?php endwhile; ?>
        <div class='clearfix'></div>
        <?php showPageNavigation($page, $pages, '/thu-vien/'.$id.'/'); ?>
    <?php endif; ?>
<?php endif; ?>
<style>
	#content .box_product {
		height:299px;
	}
	
	#content .box_product .box_product_title {
		height:15px;
		font-family: "Open Sans", sans-serif;
		text-shadow: 1px 1px 1px rgba(89,89,89,0.3);
		text-transform: none;
		font-weight: bold;
		line-height: 21px;
		font-size: 14px;
		color: #002c7d;
		overflow:hidden;
	}
	
	#content .box_product .box_product_title a {
		color: #002c7d;
	}
	#content .box_product .box_product_title a:hover {
		color: #c00;
	}
</style>